/*
 * Copyright (c) 2018.
 * http://www.ulabcare.com
 */

package com.mt.roll.passport.listener;

import com.mt.roll.core.dto.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.session.Session;
import org.springframework.session.events.SessionCreatedEvent;
import org.springframework.stereotype.Component;

/**
 * @author jiff
 * @date 2018-12-12
 * @since 1.0
 */
@Slf4j
@Component
public class SessionCreatedEventListener implements ApplicationListener<SessionCreatedEvent> {
    /**
     * Handle an application event.
     *
     * @param event the event to respond to
     */
    @Override
    public void onApplicationEvent(SessionCreatedEvent event) {
        String sessionId = event.getSessionId();
        Session session = event.getSession();
        log.info("创建会话[{}]，用户信息:{}", sessionId, session.getAttribute(LoginUser.HTTP_HEADER_NAME));
        //session.setMaxInactiveInterval(Duration.ofSeconds(5L)); 无用设置
    }
}
